package com.hean.util;

import java.util.ArrayList;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import com.hean.entity.Item;
import com.hean.entity.Resource;

public class XMLContentHandler extends DefaultHandler {
	private Resource resource;
	private Item item;
	
	public Resource getResource() {
		return resource;
	}
	
	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		if("I".equals(localName)&&resource!=null){
			item=new Item();
			item.setId(new Integer(attributes.getValue(0)));
			item.setName(attributes.getValue(1));
			item.setCn(attributes.getValue(2));
			resource.getItems().add(item);
		}else if("R".equals(localName)){
			resource=new Resource();
			resource.setCn(attributes.getValue(0));
			resource.setP(attributes.getValue(1));
			resource.setItems(new ArrayList<Item>());
		}
	}
	
}
